//package com.rp.common.config.cors;
//
//import org.springframework.core.annotation.Order;
//
//import javax.servlet.*;
//import javax.servlet.annotation.WebFilter;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//
///**
// * 类说明:
// *
// * @author ****
// * @date 2021-01-26 16:03  新建
// */
//@Order(0)
//@WebFilter(urlPatterns = "/*", filterName = "CORSFilter")
//public class CORSFilter implements Filter {
//    @Override
//    public void destroy() {
//    }
//
//    /**
//     * 此过滤器只是处理跨域问题
//     *
//     * @param servletRequest
//     * @param servletResponse
//     * @param chain
//     * @throws ServletException
//     * @throws IOException
//     */
//    @Override
//    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws ServletException, IOException {
//        HttpServletRequest req = (HttpServletRequest) servletRequest;
//        HttpServletResponse resp = (HttpServletResponse) servletResponse;
//        String origin = req.getHeader("Origin");
//        if (origin == null) {
//            origin = req.getHeader("Referer");
//        }
//        System.out.println(origin);
//
//
//        //跨域 Header
//
//        resp.setHeader("Access-Control-Allow-Methods", "*");
//
//        resp.setHeader("Access-Control-Expose-Headers", "Content-Type,XFILENAME,XFILECATEGORY,XFILESIZE");
//        resp.setHeader("Access-Control-Expose-Headers", "Access-Control-Allow-Credentials");
//        resp.setHeader("Access-Control-Expose-Headers", "Set-Cookie");
//        resp.setHeader("Access-Control-Expose-Headers", "Date");
//
//
//        resp.setHeader("Access-Control-Allow-Origin", origin);//这里不能写*，*代表接受所有域名访问，如写*则下面一行代码无效。谨记
//        resp.setHeader("Access-Control-Allow-Credentials", "true");//true代表允许携带cookie
//
//        chain.doFilter(servletRequest, servletResponse);
//    }
//
//    @Override
//    public void init(FilterConfig filterConfig) throws ServletException {
//    }
//}
